/////////SAMPLE 2.

/////////find and install needed commands.
//////code for recoding variables to 0-1 interval
//////follow instructions that come up to install:
findit _gstd01	
//////install mediation analysis code:
///(1) download <sgmediation2.ado> from replication archive for this study
///(2) In Stata, type "sysdir" (no quotes) in command window, hit return
///(3) Find the path/folder labeled PERSONAL
///(4) Copy <sgmediation2.ado> into this folder	
	
/////////DEFINE VARIABLES
	
///system identity threat:
egen sitavg=rmean(sys1-sys6)
gen sitavg2=8-sitavg
egen rsit=std01(sitavg2)

///gender:
gen male=2-QG9
///race:
gen white=.
replace white = 1 if QG15_1 ==1
replace white = 0 if QG15_2 ==1 | QG15_3 ==1 | QG15_4 ==1 | QG15_5 ==1 | QG15_6 ==1 
///education:
recode QG11 (1/8=1 "No HS diploma or GED") (9=2 "HS diploma or GED") (10/11=3 "Some college or Associate's") ///
	(12=4 "Bachelor's degree") (13/15=5 "Post-Bachelor's degree") (16=.) (.=.), generate(G11)
gen educ=(G11-1)/4
///income:
recode QG12 (1/4=1 "Under $15,000") (5/8=2 "$15,000-24,999") (9/14=3 "$25,000-49,999") ///
	(15/22=4 "$50,000-99,999") (23/28=5 "Over $100,000") (.=.), generate(G12)
gen income2=(G12-1)/4

///political information:
gen pksum=f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14
egen polknow=std01(pksum)

///authoritarianism:
gen E4a = QE4a
recode E4a 1=0 2=1
gen E4b = QE4b
recode E4b 1=1 2=0
gen E4c = QE4c
recode E4c 1=1 2=0
gen E4d = QE4d
recode E4d 1=0 2=1
egen auth=rmean(E4a E4b E4c E4d) 

///ideology:
gen rideo=(ideo7-1)/6

///ideological extremity:
gen ridex=abs(rideo-.5)
gen ridex01=ridex/.5

///conspiratorial thinking:
///all original items recoded into same variable names.
egen conthink=rmean(conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17)

///non-ideological CT endorsement:
///all items coded into same variable names so that high scores = greater endorsement.
egen cnonp=rmean(conspiracy6 conspiracy10 conspiracy12)

///liberal CT endorsement:
///all items coded into same variable names so that high scores = greater endorsement.
egen cdem=rmean(conspiracy3 conspiracy5 conspiracy11)

///conservative CT endorsement:
///all items coded into same variable names so that high scores = greater endorsement.
egen crep=rmean (conspiracy1 conspiracy2 conspiracy7 conspiracy9)

///missing-value indicator:
egen miss=rowmiss(conthink cnonp crep cdem rsit age white male income educ auth polknow rideo ridex01)

/////////DATA ANALYSIS

//////Table 1, bottom panel:
pwcorr rsit polknow auth rideo ridex conthink cnonp crep cdem if miss==0, sig

//////Table 3:
///conspiratorial thinking
reg conthink rsit age white male income educ auth polknow rideo ridex01, hc3
reg conthink rsit age white male income educ auth polknow rideo ridex01, hc3 beta
display e(r2_a)
///General CT endorsement
reg cnonp rsit age white male income educ auth polknow rideo ridex01, hc3
reg cnonp rsit age white male income educ auth polknow rideo ridex01, hc3 beta
display e(r2_a)

//////Figure 2:
reg conthink c.rsit age white male income educ c.auth c.polknow c.rideo c.ridex01, hc3
quietly margins, at(rsit=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("System Identity Threat", color(black) size(large)) ///
	xtitle("") ytitle("Conspiratorial Thinking") saving (ctk12, replace)
quietly margins, at(auth=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Authoritarianism", color(black) size(large)) ///
	xtitle("") ytitle("Conspiratorial Thinking") saving (ctk22, replace)
quietly margins, at(polknow=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Political Information", color(black) size(large)) ///
	xtitle("") ytitle("Conspiratorial Thinking") saving (ctk32, replace)	
quietly margins, at(rideo=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideology", color(black) size(large)) ///
	xtitle("") ytitle("Conspiratorial Thinking") saving (ctk42, replace)		
quietly margins, at(ridex01=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideological Extremity", color(black) size(large)) ///
	xtitle("") ytitle("Conspiratorial Thinking") saving (ctk52, replace)
graph combine ctk12.gph ctk32.gph ctk22.gph ctk42.gph ctk52.gph, title("Conspiratorial Thinking", color(black) size(huge)) ///
	cols(5) altshrink ycommon xsize(5) ysize(1) graphr(color(white)) saving(ctks2, replace)	
reg cnonp c.rsit age white male income educ c.auth c.polknow c.rideo c.ridex01, hc3
quietly margins, at(rsit=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("System Identity Threat", color(black) size(large)) ///
	xtitle("") ytitle("General CT Endorsement") saving (gct12, replace)
quietly margins, at(auth=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Authoritarianism", color(black) size(large)) ///
	xtitle("") ytitle("General CT Endorsement") saving (gct22, replace)
quietly margins, at(polknow=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Political Information", color(black) size(large)) ///
	xtitle("") ytitle("General CT Endorsement") saving (gct32, replace)	
quietly margins, at(rideo=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideology", color(black) size(large)) ///
	xtitle("") ytitle("General CT Endorsement") saving (gct42, replace)		
quietly margins, at(ridex01=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideological Extremity", color(black) size(large)) ///
	xtitle("") ytitle("General CT Endorsement") saving (gct52, replace)	
graph combine gct12.gph gct32.gph gct22.gph gct42.gph gct52.gph, title("General CT Endorsement", color(black) size(huge)) ///
	cols(5) altshrink ycommon xsize(5) ysize(1) graphr(color(white)) saving(gcts2, replace)
graph combine ctks2.gph gcts2.gph, graphr(color(white))  altshrink ycommon cols(1) xsize(5) ysize(2) /// 
	saving(table3, replace)	

//////Table 4:	
///Endorsement of "conservative" CTs:
reg crep rsit age white male income educ auth polknow rideo ridex01, hc3
reg crep rsit age white male income educ auth polknow rideo ridex01, hc3 beta
display e(r2_a)
///Endorsement of "liberal" CTs:
reg cdem rsit age white male income educ auth polknow rideo ridex01, hc3
reg cdem rsit age white male income educ auth polknow rideo ridex01, hc3 beta
display e(r2_a)
	
//////Figure 3:
reg crep c.rsit age white male income educ c.auth c.polknow c.rideo c.ridex01, hc3
quietly margins, at(rsit=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("System Identity Threat", color(black) size(large)) ///
	xtitle("") ytitle("Conservative CT Endorsement") saving (ctk13, replace)
quietly margins, at(auth=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Authoritarianism", color(black) size(large)) ///
	xtitle("") ytitle("Conservative CT Endorsement") saving (ctk23, replace)
quietly margins, at(polknow=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Political Information", color(black) size(large)) ///
	xtitle("") ytitle("Conservative CT Endorsement") saving (ctk33, replace)	
quietly margins, at(rideo=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideology", color(black) size(large)) ///
	xtitle("") ytitle("Conservative CT Endorsement") saving (ctk43, replace)		
quietly margins, at(ridex01=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideological Extremity", color(black) size(large)) ///
	xtitle("") ytitle("Conservative CT Endorsement") saving (ctk53, replace)
graph combine ctk13.gph ctk33.gph ctk23.gph ctk43.gph ctk53.gph, title("Conservative CT Endorsement", color(black) size(huge)) ///
	cols(5) altshrink ycommon xsize(5) ysize(1) graphr(color(white)) saving(ctks3, replace)	
reg cdem c.rsit age white male income educ c.auth c.polknow c.rideo c.ridex01, hc3
quietly margins, at(rsit=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("System Identity Threat", color(black) size(large)) ///
	xtitle("") ytitle("Liberal CT Endorsement") saving (gct13, replace)
quietly margins, at(auth=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Authoritarianism", color(black) size(large)) ///
	xtitle("") ytitle("Liberal CT Endorsement") saving (gct23, replace)
quietly margins, at(polknow=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Political Information", color(black) size(large)) ///
	xtitle("") ytitle("Liberal CT Endorsement") saving (gct33, replace)	
quietly margins, at(rideo=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideology", color(black) size(large)) ///
	xtitle("") ytitle("Liberal CT Endorsement") saving (gct43, replace)		
quietly margins, at(ridex01=(0(.1)1))
marginsplot, recast(line) recastci(rline) plotop(lcolor(black)) ciopt(color(gs8) lp(dash))  ///
	ylabel(0 (.2) 1, gmin gmax nogex) xlabel (0 (.2) 1) graphr(c(white) lc(white)) plotr(lc(black)) ///
	title ("Ideological Extremity", color(black) size(large)) ///
	xtitle("") ytitle("Liberal CT Endorsement") saving (gct53, replace)	
graph combine gct13.gph gct33.gph gct23.gph gct43.gph gct53.gph, title("Liberal CT Endorsement", color(black) size(huge)) ///
	cols(5) altshrink ycommon xsize(5) ysize(1) graphr(color(white)) saving(gcts3, replace)
graph combine ctks3.gph gcts3.gph, graphr(color(white)) altshrink ycommon cols(1) xsize(5) ysize(2) /// 
	saving(table4, replace)	

//////Mediation analysis (Table 5, bottom panel):
///mediation analysis: General CT endorsement
sgmediation2 cnonp, mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex01)
bootstrap r(ind_eff) r(dir_eff) r(tot_eff), reps(10000) nodots: sgmediation2 cnonp, ///
	mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex01)	
///mediation analysis: conservative CTs.
sgmediation2 crep, mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex)
bootstrap r(ind_eff) r(dir_eff) r(tot_eff), reps(10000) nodots: sgmediation2 crep, ///
	mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex01)
///mediation analysis: liberal CTs.
sgmediation2 cdem, mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex)
bootstrap r(ind_eff) r(dir_eff) r(tot_eff), reps(10000) nodots: sgmediation2 cdem, ///
	mv(conthink) iv(rsit) cv(age white male income educ auth polknow rideo ridex01)	

//////APPENDIX:
///Exploratory factor analysis on conspiratorial thinking items:	
///(reverse-coded items are 2, 6, 10, 14, 16, and 17)
factor conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17 if miss==0, ipf
factor conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17 if miss==0, ipf factors(2)
rotate, oblique oblimin(-.5)
	
///Confirmatory factor analyses on dependent variables (4 factors vs 1 factor), with error covariances:
quietly sem (GCT -> conspiracy6 conspiracy10 conspiracy12) ///
	(CCT -> conspiracy1 conspiracy2 conspiracy9 conspiracy7) ///
	(LCT -> conspiracy3 conspiracy5 conspiracy11) ///
	(CTS -> conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17) if miss==0, ///
	cov(e.conspthink16*e.conspthink17) ///
	cov(e.conspthink10*e.conspthink14) ///
	cov(e.conspthink4*e.conspthink13) ///
	cov(e.conspthink2*e.conspthink6) ///
	cov(e.conspthink6*e.conspthink10) ///
	cov(e.conspthink1*e.conspthink3) ///
	cov(e.conspthink14*e.conspthink16) ///
	cov(e.conspthink14*e.conspthink15)
estat gof, stats(chi2 rmsea res ic indices)	
quietly sem (ALL -> conspiracy6 conspiracy10 conspiracy12 ///
	conspiracy1 conspiracy2 conspiracy9 conspiracy7 ///
	conspiracy3 conspiracy5 conspiracy11 ///
	conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17) if miss==0, ///
	cov(e.conspthink16*e.conspthink17) ///
	cov(e.conspthink10*e.conspthink14) ///
	cov(e.conspthink4*e.conspthink13) ///
	cov(e.conspthink2*e.conspthink6) ///
	cov(e.conspthink6*e.conspthink10) ///
	cov(e.conspthink1*e.conspthink3) ///
	cov(e.conspthink14*e.conspthink16) ///
	cov(e.conspthink14*e.conspthink15)
estat gof, stats(chi2 rmsea res ic indices)

///Confirmatory factor analyses on dependent variables (4 factors vs 1 factor), no error covariances:
sem (GCT -> conspiracy6 conspiracy10 conspiracy12) ///
	(CCT -> conspiracy1 conspiracy2 conspiracy9 conspiracy7) ///
	(LCT -> conspiracy3 conspiracy5 conspiracy11) ///
	(CTS -> conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17) if miss==0
estat gof, stats(chi2 rmsea res ic indices)	
sem (ALL -> conspiracy6 conspiracy10 conspiracy12 ///
	conspiracy1 conspiracy2 conspiracy9 conspiracy7 ///
	conspiracy3 conspiracy5 conspiracy11 ///
	conspthink1 conspthink2 conspthink3 conspthink4 conspthink5 conspthink6 conspthink7 conspthink8 ///
	conspthink9 conspthink10 conspthink11 conspthink12 conspthink13 conspthink14 conspthink15 ///
	conspthink16 conspthink17) if miss==0
estat gof, stats(chi2 rmsea res ic indices)	

///Exploratory factor analysis on system identity threat items:
factor sys1 sys2 sys3 sys4 sys5 sys6 if miss==0, ipf	
